/*
 * PanelPersp.java
 *
 * Created on 2008年4月6日, 下午8:37
 */

package GUI;

import Global.Global;
import Manager.Manager;

/**
 *
 * @author  littlechild
 */
public class PanelPersp extends javax.swing.JPanel {
    
    Manager manager;
    PanelCavas drawcavas;
    /** Creates new form PanelPersp */
    double scale=10;
    static final int maxS=500;
    static final int defaultS=300;
    static final int minS=0;
    static final int maxTheta=90;
    static final int defaultTheta=0;
    static final int minTheta=-90;
    static final int maxPhi=90;
    static final int defaultPhi=0;
    static final int minPhi=0;
    static final int maxF=500;
    static final int defaultF=200;
    static final int minF=0;
    boolean isInitiating=true;
    public PanelPersp(Manager mg,PanelCavas pc) {
        manager=mg;
        drawcavas=pc;
        initComponents();
        init();
    }

    private void init() {
        isInitiating=true;
        this.jSliderS.setMaximum(maxS);
        this.jSliderS.setMinimum(minS);
        this.jSliderS.setValue(defaultS);
        this.jSliderTheta.setMaximum(maxTheta);
        this.jSliderTheta.setMinimum(minTheta);
        this.jSliderTheta.setValue(defaultTheta);
        this.jSliderPhi.setMaximum(maxPhi);
        this.jSliderPhi.setMinimum(minPhi);
        this.jSliderPhi.setValue(defaultPhi);
        this.jSliderF.setMaximum(maxF);
        this.jSliderF.setMinimum(minF);
        this.jSliderF.setValue(defaultF);
        isInitiating=false;
    }
    
    double sliderValue2realValue(int a) {
        return a/scale;
    }
    private void preview() {
        if(isInitiating)
            return;
        String paras[]=new String[]{
            String.valueOf(sliderValue2realValue(this.jSliderS.getValue())),
            String.valueOf(this.jSliderPhi.getValue()),
            String.valueOf(this.jSliderTheta.getValue()),
            String.valueOf(sliderValue2realValue(this.jSliderF.getValue()))
        };
        this.drawcavas.setImage(
                manager.operate(Global.opPerspective, paras,true));
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jSliderS = new javax.swing.JSlider();
        jSliderPhi = new javax.swing.JSlider();
        jSliderTheta = new javax.swing.JSlider();
        jSliderF = new javax.swing.JSlider();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jLabelS = new javax.swing.JLabel();
        JLabelPhi = new javax.swing.JLabel();
        jLabelTheta = new javax.swing.JLabel();
        jLabelf = new javax.swing.JLabel();

        jSliderS.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jSliderSMouseReleased(evt);
            }
        });
        jSliderS.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jSliderSStateChanged(evt);
            }
        });

        jSliderPhi.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jSliderPhiMouseReleased(evt);
            }
        });
        jSliderPhi.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jSliderPhiStateChanged(evt);
            }
        });

        jSliderTheta.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jSliderThetaMouseReleased(evt);
            }
        });
        jSliderTheta.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jSliderThetaStateChanged(evt);
            }
        });

        jSliderF.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jSliderFMouseReleased(evt);
            }
        });
        jSliderF.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jSliderFStateChanged(evt);
            }
        });

        jLabel1.setText("距离：");

        jLabel2.setText("俯仰角：");

        jLabel3.setText("水平：");

        jLabel4.setText("焦距：");

        jButton1.setText("确定");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("取消");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jLabelS.setText("jLabel5");

        JLabelPhi.setText("jLabel6");

        jLabelTheta.setText("jLabel7");

        jLabelf.setText("jLabel8");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(73, 73, 73)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabelf)
                            .addComponent(jLabelTheta)
                            .addComponent(JLabelPhi)
                            .addComponent(jLabelS)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(73, 73, 73)
                        .addComponent(jSliderTheta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(73, 73, 73)
                        .addComponent(jSliderPhi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(73, 73, 73)
                        .addComponent(jSliderS, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(73, 73, 73)
                        .addComponent(jSliderF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(102, 102, 102)
                        .addComponent(jButton1)
                        .addGap(28, 28, 28)
                        .addComponent(jButton2)))
                .addContainerGap(71, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(34, 34, 34)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jLabelS))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSliderS, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(12, 12, 12)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(JLabelPhi))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSliderPhi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jLabelTheta))
                .addGap(7, 7, 7)
                .addComponent(jSliderTheta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jLabelf))
                .addGap(7, 7, 7)
                .addComponent(jSliderF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jSliderSStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jSliderSStateChanged
        // TODO add your handling code here:
        this.jLabelS.setText(String.valueOf(sliderValue2realValue(this.jSliderS.getValue())));
}//GEN-LAST:event_jSliderSStateChanged

    private void jSliderPhiStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jSliderPhiStateChanged
        // TODO add your handling code here:
        this.JLabelPhi.setText(String.valueOf(this.jSliderPhi.getValue()));
    }//GEN-LAST:event_jSliderPhiStateChanged

    private void jSliderThetaStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jSliderThetaStateChanged
        // TODO add your handling code here:
        this.jLabelTheta.setText(String.valueOf(this.jSliderTheta.getValue()));
    }//GEN-LAST:event_jSliderThetaStateChanged

    private void jSliderFStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jSliderFStateChanged
        // TODO add your handling code here:
        this.jLabelf.setText(String.valueOf(sliderValue2realValue(this.jSliderF.getValue())));
    }//GEN-LAST:event_jSliderFStateChanged

    private void jSliderSMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jSliderSMouseReleased
        // TODO add your handling code here:
        preview();
    }//GEN-LAST:event_jSliderSMouseReleased

    private void jSliderPhiMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jSliderPhiMouseReleased
        // TODO add your handling code here:
        preview();
    }//GEN-LAST:event_jSliderPhiMouseReleased

    private void jSliderThetaMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jSliderThetaMouseReleased
        // TODO add your handling code here:
        preview();
    }//GEN-LAST:event_jSliderThetaMouseReleased

    private void jSliderFMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jSliderFMouseReleased
        // TODO add your handling code here:
        preview();
    }//GEN-LAST:event_jSliderFMouseReleased

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        String paras[]=new String[]{
            String.valueOf(sliderValue2realValue(this.jSliderS.getValue())),
            String.valueOf(this.jSliderPhi.getValue()),
            String.valueOf(this.jSliderTheta.getValue()),
            String.valueOf(sliderValue2realValue(this.jSliderF.getValue()))
        };
        this.drawcavas.setImage(
                manager.operate(Global.opPerspective, paras));
        CommonFunc.disposeFrame(this);
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:d
        this.drawcavas.setImage(
                manager.operate(Global.opNone, null));
        CommonFunc.disposeFrame(this);
    }//GEN-LAST:event_jButton2ActionPerformed
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel JLabelPhi;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabelS;
    private javax.swing.JLabel jLabelTheta;
    private javax.swing.JLabel jLabelf;
    private javax.swing.JSlider jSliderF;
    private javax.swing.JSlider jSliderPhi;
    private javax.swing.JSlider jSliderS;
    private javax.swing.JSlider jSliderTheta;
    // End of variables declaration//GEN-END:variables
   
}
